function translateBase64ImgToFile(base64: string, filename: string, contentType: any) {
  var arr = base64.split(',')  //去掉base64格式图片的头部
  var bstr = atob(arr[1])   //atob()方法将数据解码
  var leng = bstr.length
  var u8arr = new Uint8Array(leng)
  while (leng--) {
    u8arr[leng] = bstr.charCodeAt(leng) //返回指定位置的字符的 Unicode 编码
  }
  return new File([u8arr], filename, { type: contentType })
}
function urlToFile(url: string, name: string, type: any) {
  return new Promise(resolve => {
    let img = new Image() //通过构造函数绘制图片实例
    img.crossOrigin = 'Anonymous' //处理图片跨域问题，见拓展1
    img.src = url
    img.onload = () => {
      var canvas = document.createElement('canvas')
      var context = canvas.getContext('2d')
      //该加载过程为异步事件，请先确保获取完整图片
      canvas.width = img.width
      canvas.height = img.height
      context?.drawImage(img, 0, 0) //将图片绘制在canvas中
      var URLData = canvas.toDataURL('image/png')
      // console.log(URLData)
      resolve(translateBase64ImgToFile(URLData, name, type))
    }
  })
}
export { translateBase64ImgToFile, urlToFile }